package org.cbg.panel;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
import java.io.IOException;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

import org.cbg.entity.Salegoods;
import org.cbg.frame.TrslationMainJframe;
import org.come.Frame.ZhuFrame;
import org.come.entity.Goodstable;
import org.come.model.Lingbao;
import org.come.until.GoodsListFromServerUntil;
import org.come.until.Goodtype;

import com.tool.role.RoleLingFa;



/**
 * 我要卖 寄售商品 物品分类 面板
 * 
 * @author Administrator
 * 
 */
public class TraslationWantSendJishoushangpinFenleiWupinJpanel extends JPanel {
    // 0是物品 1是灵宝
    private int type = 0;
    private int ys;
    private JLabel[] labels;

    public TraslationWantSendJishoushangpinFenleiWupinJpanel() {
        // TODO Auto-generated constructor stub
        this.setPreferredSize(new Dimension(385, 240));
        this.setBackground(null);
        this.setOpaque(false);
        this.setLayout(null);

        labels = new JLabel[40];
        for (int i = 0; i < 40; i++) {
            labels[i] = new JLabel();
            labels[i].setBounds((i % 8) * 48, (i / 8) * 48, 48, 48);
            labels[i].addMouseListener(new gz(i));
            this.add(labels[i]);
        }
    }

    private ImageIcon icon;

    @Override
    protected void paintComponent(Graphics g) {
        // TODO Auto-generated method stub
        super.paintComponent(g);
        if (icon == null) {
            icon = new ImageIcon("inkImg/number/b4/wpxsk.png");
        }
        g.drawImage(icon.getImage(), 0, 0, 385, 240, this);
        if (type == 0) {
            GoodsListFromServerUntil.drawCBG(g, 2, 2, ys);
        } else if (type == 1) {
            RoleLingFa.getRoleLingFa().drawCBG(g, 2, 2, ys);
        }



    }

    public void change(int type) {
        this.ys = 0;
        this.type = type;
    }

    class gz implements MouseListener {
        private int p;

        public gz(int p) {
            super();
            this.p = p;
        }

        @Override
        public void mouseClicked(MouseEvent e) {
        }

        @Override
        public void mousePressed(MouseEvent e) {
            Salegoods salegoods = new Salegoods();
            // 2大话币，3道具，5装备，6灵宝，4召唤兽
            if (type == 0) {
                Goodstable good = GoodsListFromServerUntil.getCBG(ys, p);
                if (good == null) {
                    return;
                }
                int Equipment = Goodtype.EquipmentType(good.getType());
                if (Equipment == -1) {
                    salegoods.setSaletype(3);
                } else {
                    salegoods.setSaletype(5);
                }
                salegoods.setSalename(good.getGoodsname());
                salegoods.setOtherid(good.getRgid());
                salegoods.setSaleskin(good.getSkin());
            } else {
                Lingbao lingbao = RoleLingFa.getRoleLingFa().getCBG(ys, p);
                if (lingbao == null) {
                    return;
                }
                salegoods.setSalename(lingbao.getBaoname());
                salegoods.setSaletype(6);
                salegoods.setOtherid(lingbao.getBaoid());
                salegoods.setSaleskin(lingbao.getSkin());
            }
            TraslationWantSendCardJpanel traslationWantSendCardJpanel = TrslationMainJframe.getTrslationMainJframe().getTrslationMainJpanel().getTranslationMainCardJpanel().getTraslationWantSentJpanel().getTraslationWantSendCardJpanel();
            traslationWantSendCardJpanel.getTraslationWantSendJishoushangpinJpanel()
                    .thGood(salegoods);
        }

        @Override
        public void mouseReleased(MouseEvent e) {
        }

        @Override
        public void mouseEntered(MouseEvent e) {
            if (type == 0) {
                Goodstable good = GoodsListFromServerUntil.getCBG(ys, p);
                if (good == null) {
                    return;
                }
                ZhuFrame.getZhuJpanel().creatgoodtext(good);
            } else {
                Lingbao lingbao = RoleLingFa.getRoleLingFa().getCBG(ys, p);
                if (lingbao == null) {
                    return;
                }
                ZhuFrame.getZhuJpanel().creatlingtext(lingbao);
            }
        }

        @Override
        public void mouseExited(MouseEvent e) {
            if (type == 0) {
                ZhuFrame.getZhuJpanel().cleargoodtext();
            } else {
                ZhuFrame.getZhuJpanel().clearlingtext();
            }
        }

    }
}
